﻿using SIGBugs.Shared.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SIGBugs.Shared.Models
{
    [Table("TaskSet")]
    public class Task
    {
        [Key]
        public int Id { get; set; }
        [Required]
        public string  Title { get; set; }
        public string Body { get; set; }
        public TaskType TaskType { get; set; }
        public string CreatedBy { get; set; }
        [Required]
        public DateTime CreatedDate { get; set; }
        public string Performer { get; set; }
        public TaskStatus Status { get; set; }

        public int ProjectId { get; set; }
        public virtual Project Project { get; set; }
        [NotMapped]
        public string StatusText
        {
            get
            {
                var enumType = typeof(TaskStatus);
                var field = enumType.GetFields()
                           .First(x => x.Name == System.Enum.GetName(enumType, Status));
                var attribute = field.GetCustomAttribute<DisplayAttribute>();
                return attribute.Name;

            }
        }
        [NotMapped]
        public string TypeText
        {
            get
            {
                var enumType = typeof(TaskType);
                var field = enumType.GetFields()
                           .First(x => x.Name == System.Enum.GetName(enumType, TaskType));
                var attribute = field.GetCustomAttribute<DisplayAttribute>();
                return attribute.Name;

            }
        }

    }
}
